import axios from 'axios';
import { stringify } from 'querystring';
import { getStorage } from '@/utils/storage';
export default function myAxios(url, method, data, noToken) {
  let Authentication = {};
  if (!noToken) {
    Authentication = { Authentication: getStorage('token') };
    // console.log('Authentication',Authentication);
  }
  let dataObj = {};
  if (/^get$/i.test(method)) {
    dataObj = { params: stringify(data) };
  } else if (/^(post|delete|put)$/i.test(method)) {
    dataObj = { data: stringify(data) };
  } else {
    throw new Error('不是get、post、delete、put请求');
  }
  return axios({
    url,
    method,
    headers: {
      'content-type': 'application/x-www-form-urlencoded',
      ...Authentication,
    },
    ...dataObj,
  });
}
